<?php

namespace app\aqara\controller;

use support\Request;
use app\controller\AqaraBaseController;

class AqaraSwitchController
{
    protected $noNeedLogin = ['index','setStatus'];
    public function index(Request $request)
    {
        $a = new AqaraBaseController();
        $b = $a->index('');
        return json($b);
        // return response(__CLASS__);
    }
    //控制插座开关
    public function setStatus(Request $request){
        $user_id = 1;
        $subjectId = $request->post('subjectId','');
        if(!$subjectId){
            return json(['code'=>0,'msg'=>'缺失参数subjectId']);
        }
        $Appid = $request->post('Appid','');
        if(!$Appid){
            return json(['code'=>0,'msg'=>'缺失参数Appid']);
        }
        $Keyid = $request->post('Keyid','');
        if(!$Keyid){
            return json(['code'=>0,'msg'=>'缺失参数Keyid']);
        }
        $appKey = $request->post('appKey','');
        if(!$appKey){
            return json(['code'=>0,'msg'=>'缺失参数appKey']);
        }
        $status = $request->post('status',0);
        $AqaraBase = new AqaraBaseController();
        $token = $AqaraBase->getAccesstoken($user_id,$Appid,$Keyid,$appKey);
        if($token['code']==0){
            return json(['code'=>0,'msg'=>$token['msg']]);
        }
        $Accesstoken = $token['data'];
        $resourceId = '4.1.85';
        $res = $AqaraBase->yinshechazuo('write.resource.device',$subjectId,$resourceId,$status,$Appid,$Keyid,$appKey,$Accesstoken);
        return json($res);

    }
    //查询设备最新状态
    

}
